﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Rabbit.Contracts.Interface;
using Rabbit.Domain.Entity;

namespace Rabbit.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BreedController : ControllerBase
    {
        private readonly IBreedService _breedService;
        private readonly ILogger<BreedController> _logger;

        public BreedController(IBreedService breedService, ILogger<BreedController> logger)
        {
            _breedService = breedService;
            _logger = logger;
        }

        /// <summary>
        /// 上传图片（多）
        /// </summary>
        /// <param name="file">文件名</param>
        /// <returns>文件的路径</returns>
        [HttpPost]
        public async Task<string> UploadFile(IFormFile file)
        {

            // 指定图片上传目录
            var uploadDir = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images");

            // 如果目录不存在则创建
            if (!Directory.Exists(uploadDir))
            {
                Directory.CreateDirectory(uploadDir);
            }

            // 生成唯一的文件名
            var uniqueFileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Path.GetExtension(file.FileName).ToLower();

            var filePath = Path.Combine(uploadDir, uniqueFileName);

            // 使用文件流将图片保存到指定路径
            using (var stream = new FileStream(filePath, FileMode.Create))
            {
                await file.CopyToAsync(stream);
            }
            // 图片保存路径
            var relativePath = Path.Combine(uniqueFileName);

            // 可以将 filePath 存入数据库或返回视图显示图片等操作
            return (relativePath);
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="breed"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult GetBreedAdd(Breed breed)
        {
            var list=_breedService.GetBreedAdd(breed);
            return Ok(list);
        }

        /// <summary>
        /// 显示
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult   GetBreedShow(int id)
        {
            var list=_breedService.GetBreedShow(id);
            return Ok(list);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="breed"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult GetBreedUpd(Breed breed)
        {
            var list=_breedService.GetBreedUpd(breed);
            return Ok(list);
        }

        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetBreedFind(int id)
        {
            var list=_breedService.GetBreedFind(id);
            return Ok(list);
        }

        /// <summary>
        /// 保健添加
        /// </summary>
        /// <param name="health"></param>
        /// <returns></returns>
        [HttpPost]

        public IActionResult GetHealthAdd(Health health)
        {
           var list=_breedService.GetHealthAdd(health);
            return Ok(list);
        }

        /// <summary>
        /// 保健删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>

        [HttpPost]
        public IActionResult GetHealthDel(int id)
        {
            var list=_breedService.GetHealthDel(id);
            return Ok(list);
        }

        /// <summary>
        /// 保健显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetHealthShow()
        {
            var list = _breedService.GetHealthShow();
            return Ok(list);
        }

        /// <summary>
        /// 保健修改
        /// </summary>
        /// <param name="health"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult GetHealthUpd(Health health)
        {
            var list=_breedService.GetHealthUpd(health);
            return Ok(list);
        }

        /// <summary>
        /// 保健反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetHealthFind(int id)
        {
            var list = _breedService.GetHealthFind(id);
            return Ok(list);
        }

        /// <summary>
        /// 养殖公司显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetYcompanShow()
        {
           var list=_breedService.GetYcompanShow();
            return Ok(list);
        }

        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetYcompanyFind(int id)
        {
           var list=_breedService.GetYcompanyFind(id);
            return Ok(list);
        }

        /// <summary>
        /// 养殖修改
        /// </summary>
        /// <param name="ycompany"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult GetYcompanyUpd(Ycompany ycompany)
        {
           var list=_breedService.GetYcompanyUpd(ycompany);
            return Ok(list);
        }


        /// <summary>
        /// 动检添加
        /// </summary>
        /// <param name="animal"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult GetAnimalAdd(Animal animal)
        {
            var list=_breedService.GetAnimalAdd(animal);
            return Ok(list);
        }

        /// <summary>
        /// 动检显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetAnimalShow()
        {
            var list=_breedService.GetAnimalShow();
            return Ok(list);
        }

        /// <summary>
        /// 养殖企业照片添加
        /// </summary>
        /// <param name="yimg"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult GetYimgAdd(Yimg yimg)
        {
            var list=_breedService.GetYimgAdd(yimg);
            return Ok(list);
        }

        /// <summary>
        /// 养殖企业照片显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetYimgShow()
        {
            var list = _breedService.GetYimgShow();
            return Ok(list);
        }

    }
}
